<template>
    <div class="grade-change-rules-main">
        <div class="content">
            <div class="top_card">
                <div class="top_card_name">等级变更规则</div>
            </div>
            <div class="form_card">
                <div class="radio">
                    <div class="radio-item">
                        <el-radio v-model="formInfo.type" :label="1">根据等级规则自动升降级</el-radio>
                    </div>
                    <div class="radio-item-desc">根据等级管理设置的升级条件自动升降级。</div>
                </div>
                <div class="radio">
                    <div class="radio-item">
                        <el-radio v-model="formInfo.type" :label="2">
                            同步客易达SCRM会员等级
                            <el-tooltip
                                content="选择此项前请确保已在我的应用中绑定客易达SCRM，在等级管理中创建并启用与客易达SCRM中匹配的会员等级。"
                                placement="top">
                                <img class="radio-item-icon" src="@/assets/imgs/mall/commodity/icon_04.png" alt="" />
                            </el-tooltip>
                        </el-radio>
                    </div>
                    <div class="radio-item-desc">
                        选择此项后，会员将跟随客易达SCRM变更等级，不再根据商城等级管理中 设置的升级条件进行升降级。
                    </div>
                </div>
            </div>
            <div class="btn_card">
                <el-button type="primary" @click="onSubmit()">保存</el-button>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue';
import { ElMessage } from 'element-plus';
import { setLayout, resetLayout } from '@/hooks/layout';
import request from '@/request';

const formInfo = reactive({
    type: 1
});

const onSubmit = async () => {
    let params = {
        applyType: formInfo.type
    };
    let res = await request('setFollowRulesServ', params);
    ElMessage.success('保存成功');
};

const initData = async () => {
    let params = {
        rule: 1
    };
    let res = await request('getFollowRuleServ', params);
    formInfo.type = res.data.levelFollow;
};

onMounted(() => {
    setLayout();
    initData();
});

onUnmounted(() => {
    resetLayout();
});
</script>
<style lang="scss" src="./index.scss" scoped></style>
